<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->bigIncrements('id');

            $table->string('username')->unique();
            $table->string('phone')->unique();
            $table->string('nickname')->default("");
            $table->string('password');

            # 分佣层级
            $table->string('path')->index()->comment("这个是层级分类");
            $table->tinyInteger('level')->default(1)->comment("这个是层级");
            $table->unsignedBigInteger('parent_id')->nullable()->comment("所属上级为 null 时 为顶级");

            $table->text('token')->nullable();
            $table->string('ip')->nullable();
            $table->string('old_ip')->nullable();
            $table->timestamp('login_at')->nullable();
            $table->timestamp('old_login_at')->nullable();
            /*$table->rememberToken();*/
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
